<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            margin: 0;
            height: 10000px;
        }
        #box1, #box2{
            width: 100px;
            height: 100px;
            background-color: antiquewhite;
            position: absolute;
        }
        #box2{
            width: 50px;
            height: 50px;
            background-color: chartreuse;
        }
    </style>
</head>
<body>
    <div id="box1"></div>
    <div id="box2"></div>
    <script>
        window.onload = function(){

            var box1 = document.getElementById("box1");
            var d = document.documentElement;
            
            //绑定鼠标移动事件
            d.onmousemove = function (even){

                /**
                 * clientX与clientY用于获取鼠标在当前的可见窗的坐标
                 *  而div的偏移量，是相对于整个页面的
                 * 
                 * pageX与pageY可以获取相对于当前页面的坐标
                 *  pageX 与pgeY不兼容IE8
                 * 
                 * 
                */
                var x = even.clientX;
                var y = even.clientY;
                var a = even.pageX;
                var b = even.pageY;
 
                box1.style.left = d.scrollTop +"px";
                box1.style.top  = y +"px";

                box2.style.left = a +"px";
                box2.style.top  = b +"px";

                // console.log( x+","+y);

            }




        }
    </script>
</body>
</html>